import { post } from '@/request/http'
import { toString, setMd5 } from '@/utils/utils'
import store from '@/store'

// 查询用户列表

export const queryBasUser = ({
  dptId,
  PageSizes,
  PageIndexs
}) => post('/FTKJWLHYPT/basUser/queryBasUser?SessionId=' +
    store.state.user.SessionId_DX_H, {

  Data: {
    Parameters: {
      FTKJWLHYPT: {
        dptId,
        fltUuid: store.state.user.FLT_UUID_DX_H
      }
    },
    Orderbys: {},
    PageIndex: {
      FTKJWLHYPT: toString(PageIndexs)
    },
    PageSize: {
      FTKJWLHYPT: toString(PageSizes)
    }
  }
})

// 新增用户接口
export const addBasUser = ({
  usrCode,
  usrName,
  dptName,
  usrPassword,
  usrRles,
  usrDpts,
  usrCellphone = '',
  usrEmail = '',
  usrStatus,
  remark = '',
}) => post('FTKJWLHYPT/basUser/addBasUser?SessionId=' +
    store.state.user.SessionId_DX_H, {
  Data: {
    Parameters: {
      FTKJWLHYPT: {
        usrCode,
        usrName,
        usrPassword: setMd5(usrPassword),
        usrRles: usrRles.join(','),
        usrDpts: usrDpts.join(','),
        dptName,
        usrCellphone,
        usrEmail,
        usrStatus,
        remark,
        creator: store.state.user.USERNAME_DX_H,
        fltUuid: store.state.user.FLT_UUID_DX_H
      }
    }
  }

}
)


//编辑用户接口
export const editBasUser = ({
  uuid,
  usrCode,
  usrName,
  dptName,
  usrRles,
  usrDpts,
  usrCellphone,
  usrEmail,
  usrStatus,
  remark,
  version,
}) => post(
  'FTKJWLHYPT/basUser/editBasUser?SessionId=' +
    store.state.user.SessionId_DX_H, {

    Data: {
      Parameters: {
        FTKJWLHYPT: {
          usrCode,
          usrName,
          usrRles: usrRles.join(','),
          usrDpts: usrDpts.join(','),
          dptName,
          usrCellphone,
          usrEmail,
          usrStatus,
          remark,
          fltUuid: store.state.user.FLT_UUID_DX_H,
          lastmodifier: store.state.user.USERNAME_DX_H,
          version: String(version),
          uuid
        }
      }
    }

  }
).catch(e => {
  console.log(e)
})


// 删除用户接口
export const delBasUser = ({
  uuid,
  version
}) => post(
  'FTKJWLHYPT/basUser/delBasUser?SessionId=' + store.state.user.SessionId_DX_H, {

    Data: {
      Parameters: {
        FTKJWLHYPT: {
          uuid,
          lastModifier: store.state.user.USERNAME_DX_H,
          version: String(version)
        }
      }
    }

  }
)

//密码重置

export const resetBasUserPassWord = ({
  uuid,
  version,
}) => post('FTKJWLHYPT/basUser/resetBasUserPassWord?SessionId=' +
    store.state.user.SessionId_DX_H, {

  Data: {
    Parameters: {
      FTKJWLHYPT: {
        uuid,
        lastModifier: store.state.user.USERNAME_DX_H,
        version: String(version),
      }
    }
  }
}
)

// 供应商角色下拉菜单
export const queryrolesGys = ({
  rleCUuid
}) =>
  post(
    '/FTKJWLHYPT/system/querySysRoleList',
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            rleCUuid,//角色类型
            fltUuid: '-1' // 这里固定-1 是因为角色下拉框不区分企业
          }
        }
      }
    }
  )